var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("TrayControl"),
s = t("GameConstant"),
l = t("CarConstant"),
c = cc._decorator,
d = c.ccclass,
h = c.property,
p = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.weldJoint = null,
        e.revoluteJoint = null,
        e.leverJoint = null,
        e.collider = null,
        e.rigidBody = null,
        e.node_joint = null,
        e.node_collider = null,
        e._tagCollider = 0,
        e._carTag = 0,
        e._body = null,
        e.bCanAttack = !0,
        e._jonintBody = null,
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        this.initScale()
    },
    e.prototype.init = function(t, e, o, i) {
        if (this.initData(), this._carTag = t, this.weldJoint.connectedBody = i, this._body = i, this.node.active = !0, null == i) return this.weldJoint.node.group = "equipCarWheel",
        this.weldJoint.node.getComponent(cc.PhysicsBoxCollider).sensor = !1,
        this.leverJoint.node.group = "equipCarWheel",
        this.leverJoint.node.getComponent(cc.PhysicsBoxCollider).sensor = !1,
        this.collider.node.group = "equipCarWheel",
        void(this.collider.node.getComponent(cc.PhysicsBoxCollider).sensor = !1);
        this._carTag == s.Collide_Car_Tag.Left ? (this.collider.tag = e, this.revoluteJoint.maxMotorTorque = 0, s.Cur_Game_Type == s.Game_Type.PK ? this.weldJoint.connectedAnchor = cc.v2(o.x * s.Game_Type_Scale.PK, o.y * s.Game_Type_Scale.PK) : this.weldJoint.connectedAnchor = cc.v2(o.x, o.y)) : (this.collider.tag = e, this.revoluteJoint.motorSpeed = -this.revoluteJoint.motorSpeed, this.revoluteJoint.maxMotorTorque = 0, s.Cur_Game_Type == s.Game_Type.PK ? this.weldJoint.connectedAnchor = cc.v2( - o.x * s.Game_Type_Scale.PK, o.y * s.Game_Type_Scale.PK) : this.weldJoint.connectedAnchor = cc.v2( - o.x, o.y))
    },
    e.prototype.onMoveLeft = function() {
        if (this._carTag == s.Collide_Car_Tag.Left) {
            this.node.active = !1,
            this.node.scaleX = -Math.abs(this.node.scaleX);
            var t = this.weldJoint.connectedAnchor;
            this.weldJoint.connectedBody = this._body,
            this.node.position = cc.v3( - t.x, t.y, 0),
            this.weldJoint.connectedAnchor = cc.v2( - t.x, t.y),
            this.node.active = !0
        } else this._carTag == s.Collide_Car_Tag.Right && (this.node.scaleX = Math.abs(this.node.scaleX))
    },
    e.prototype.onMoveRight = function() {
        this._carTag == s.Collide_Car_Tag.Left ? this.node.scaleX = Math.abs(this.node.scaleX) : this._carTag == s.Collide_Car_Tag.Right && (this.node.scaleX = -Math.abs(this.node.scaleX))
    },
    e.prototype.setScale = function() {
        this.node.scaleX = -this.node.scaleX;
        var t = this.weldJoint.connectedAnchor;
        this.weldJoint.connectedAnchor = cc.v2(Math.abs(t.x), t.y),
        this.rigidBody.type = cc.RigidBodyType.Static,
        this.rigidBody.type = cc.RigidBodyType.Dynamic
    },
    e.prototype.onGameStart = function() {
        this.revoluteJoint.enableMotor = !0,
        this.revoluteJoint.node.active = !0,
        this.collider.node.active = !0,
        this.rigidBody.type = cc.RigidBodyType.Dynamic
    },
    e.prototype.onGameOver = function() {
        this.revoluteJoint.enableMotor = !1
    },
    e.prototype.onGameBoutReady = function() {
        this.node.active = !1,
        this.destroy()
    },
    e.prototype.onGameBoutStart = function() {
        this.bCanAttack = !0,
        this.revoluteJoint.enableMotor = !0,
        this.revoluteJoint.node.active = !0,
        this.collider.node.active = !0,
        this.rigidBody.type = cc.RigidBodyType.Dynamic
    },
    e.prototype.onGameBoutOver = function() {
        this.revoluteJoint.enableMotor = !1
    },
    e.prototype.onCanAttack = function(t) {
        this.bCanAttack = t
    },
    e.prototype.onUseTools = function() {
        this.bCanAttack && (this.revoluteJoint.enableMotor = !0, this.revoluteJoint.maxMotorTorque = l.GetCarToolsData(l.Tools_ID.Tray).MotorTorque, this._carTag == s.Collide_Car_Tag.Left ? this.revoluteJoint.motorSpeed = l.GetCarToolsData(l.Tools_ID.Tray).motorSpeed: this.revoluteJoint.motorSpeed = -l.GetCarToolsData(l.Tools_ID.Tray).motorSpeed)
    },
    e.prototype.onCancelUse = function() {
        this.revoluteJoint.enableMotor = !0,
        this.revoluteJoint.maxMotorTorque = 0
    },
    e.prototype.initData = function() {},
    e.prototype.initScale = function() {
        if (s.Cur_Game_Type == s.Game_Type.PK) {
            var t = this.revoluteJoint.anchor;
            this.revoluteJoint.anchor = cc.v2(t.x * s.Game_Type_Scale.PK, t.y * s.Game_Type_Scale.PK);
            var e = this.revoluteJoint.connectedAnchor;
            this.revoluteJoint.connectedAnchor = cc.v2(e.x * s.Game_Type_Scale.PK, e.y * s.Game_Type_Scale.PK),
            this.leverJoint.node.getComponent(cc.PhysicsBoxCollider);
            var o = this.leverJoint.anchor;
            this.leverJoint.anchor = cc.v2(o.x * s.Game_Type_Scale.PK, o.y * s.Game_Type_Scale.PK);
            var i = this.leverJoint.connectedAnchor;
            this.leverJoint.connectedAnchor = cc.v2(i.x * s.Game_Type_Scale.PK, i.y * s.Game_Type_Scale.PK),
            this.collider.offset.y = this.collider.offset.y * s.Game_Type_Scale.PK
        } else this.revoluteJoint.maxMotorTorque = l.GetCarToolsData(l.Tools_ID.Tray).MotorTorque
    },
    e.prototype.onAirShipIn = function() {
        this.node.active = !1
    },
    e.prototype.onAirShipOut = function() {
        this.node.active = !0
    },
    e.prototype.onDisassembly = function() {
        this.weldJoint.connectedBody = null,
        this.node.active = !1
    },
    e.prototype.getPos = function() {
        return this.weldJoint.node.convertToWorldSpaceAR(cc.Vec3.ZERO)
    },
    e.prototype.getNodePostion = function() {},
    e.prototype.setNodePostion = function() {},
    e.prototype.onCreateJonit = function() {
        this._jonintBody = this.node_joint.addComponent(cc.RigidBody);
        var t = this.node_joint.addComponent(cc.PhysicsBoxCollider);
        t.offset = cc.v2( - 76, 0),
        t.size = cc.size(190, 14);
        var e = this.node_joint.addComponent(cc.RevoluteJoint);
        e.anchor = cc.v2(9.144, 0),
        e.connectedBody = this.node.getComponent(cc.RigidBody),
        e.maxMotorTorque = 4e3,
        e.motorSpeed = 50
    },
    e.prototype.onCreateCollider = function() {
        this.node_collider.addComponent(cc.RigidBody).fixedRotation = !0;
        var t = this.node_collider.addComponent(cc.PhysicsBoxCollider);
        t.tag = this._tagCollider,
        t.offset = cc.v2(0, 11),
        t.size = cc.size(100, 10);
        var e = this.node_collider.addComponent(cc.RevoluteJoint);
        e.anchor = cc.v2(.04, -10.47),
        e.connectedAnchor = cc.v2( - 169.814, -2.474),
        e.connectedBody = this._jonintBody,
        e.maxMotorTorque = 2e3,
        e.motorSpeed = 0,
        this.node_collider.addComponent(r.default)
    },
    e.prototype.setPos = function(t) {
        this.node.position = t;
        var e = this.node.convertToWorldSpaceAR(cc.Vec2.ZERO);
        this.revoluteJoint.anchor = e
    },
    a([h(cc.WeldJoint)], e.prototype, "weldJoint", void 0),
    a([h(cc.RevoluteJoint)], e.prototype, "revoluteJoint", void 0),
    a([h(cc.RevoluteJoint)], e.prototype, "leverJoint", void 0),
    a([h(cc.PhysicsBoxCollider)], e.prototype, "collider", void 0),
    a([h(cc.RigidBody)], e.prototype, "rigidBody", void 0),
    a([h(cc.Node)], e.prototype, "node_joint", void 0),
    a([h(cc.Node)], e.prototype, "node_collider", void 0),
    a([d], e)
} (cc.Component);
o.default = p